<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>NASM编译器常用指令 | whoway</title>
    <meta name="description" content="Personal Blog Website">
    <link rel="icon" href="/images/photo.jpg">
  <link rel="manifest" href="/images/photo.jpg">
  <link rel="apple-touch-icon" href="/images/photo.jpg">
  <meta http-quiv="pragma" cotent="no-cache">
  <meta http-quiv="pragma" cotent="no-cache,must-revalidate">
  <meta http-quiv="expires" cotent="0">
    
    <link rel="preload" href="/assets/css/0.styles.0dbae9ec.css" as="style"><link rel="preload" href="/assets/js/app.c70e21ad.js" as="script"><link rel="preload" href="/assets/js/118.c6ae6572.js" as="script"><link rel="prefetch" href="/assets/js/10.15222a53.js"><link rel="prefetch" href="/assets/js/100.7e0e5a86.js"><link rel="prefetch" href="/assets/js/101.efd59f25.js"><link rel="prefetch" href="/assets/js/102.dfbdc06c.js"><link rel="prefetch" href="/assets/js/103.d3ab2109.js"><link rel="prefetch" href="/assets/js/104.117957ef.js"><link rel="prefetch" href="/assets/js/105.046e8ff3.js"><link rel="prefetch" href="/assets/js/106.aebdc17d.js"><link rel="prefetch" href="/assets/js/107.248733c2.js"><link rel="prefetch" href="/assets/js/108.a2fecadc.js"><link rel="prefetch" href="/assets/js/109.35196857.js"><link rel="prefetch" href="/assets/js/11.770642f2.js"><link rel="prefetch" href="/assets/js/110.cf3d973c.js"><link rel="prefetch" href="/assets/js/111.f985889a.js"><link rel="prefetch" href="/assets/js/112.ad614f41.js"><link rel="prefetch" href="/assets/js/113.f666653c.js"><link rel="prefetch" href="/assets/js/114.c6c3f384.js"><link rel="prefetch" href="/assets/js/115.e51d3c2f.js"><link rel="prefetch" href="/assets/js/116.4f4b39f5.js"><link rel="prefetch" href="/assets/js/117.99352e11.js"><link rel="prefetch" href="/assets/js/119.4ccbe778.js"><link rel="prefetch" href="/assets/js/12.042a92ff.js"><link rel="prefetch" href="/assets/js/120.edda1c4f.js"><link rel="prefetch" href="/assets/js/121.30a638ed.js"><link rel="prefetch" href="/assets/js/122.6efcefb1.js"><link rel="prefetch" href="/assets/js/123.91e6665b.js"><link rel="prefetch" href="/assets/js/124.f27e3d7e.js"><link rel="prefetch" href="/assets/js/125.c75712d5.js"><link rel="prefetch" href="/assets/js/126.ed756cce.js"><link rel="prefetch" href="/assets/js/127.2f06c74c.js"><link rel="prefetch" href="/assets/js/128.d5f6f30e.js"><link rel="prefetch" href="/assets/js/129.508b7eed.js"><link rel="prefetch" href="/assets/js/13.b5280c37.js"><link rel="prefetch" href="/assets/js/130.dc05f9aa.js"><link rel="prefetch" href="/assets/js/131.e0ba69b1.js"><link rel="prefetch" href="/assets/js/132.d79bcaa4.js"><link rel="prefetch" href="/assets/js/133.34acc01a.js"><link rel="prefetch" href="/assets/js/134.dabf64d5.js"><link rel="prefetch" href="/assets/js/135.ad90c915.js"><link rel="prefetch" href="/assets/js/136.dbb0074f.js"><link rel="prefetch" href="/assets/js/137.284ad365.js"><link rel="prefetch" href="/assets/js/138.a4b6856f.js"><link rel="prefetch" href="/assets/js/139.c9c1e20f.js"><link rel="prefetch" href="/assets/js/14.df02ba38.js"><link rel="prefetch" href="/assets/js/140.8b0a9269.js"><link rel="prefetch" href="/assets/js/141.9c7759c5.js"><link rel="prefetch" href="/assets/js/142.a4201a82.js"><link rel="prefetch" href="/assets/js/143.d7da6e8c.js"><link rel="prefetch" href="/assets/js/144.5e48e65d.js"><link rel="prefetch" href="/assets/js/145.a0e2633c.js"><link rel="prefetch" href="/assets/js/146.3c775f9b.js"><link rel="prefetch" href="/assets/js/147.22add89a.js"><link rel="prefetch" href="/assets/js/148.cfde1009.js"><link rel="prefetch" href="/assets/js/149.ffc835b5.js"><link rel="prefetch" href="/assets/js/15.fbdfc4ee.js"><link rel="prefetch" href="/assets/js/150.406c4b20.js"><link rel="prefetch" href="/assets/js/151.b2040eea.js"><link rel="prefetch" href="/assets/js/152.7bc65661.js"><link rel="prefetch" href="/assets/js/153.1d7c65e3.js"><link rel="prefetch" href="/assets/js/154.1309de49.js"><link rel="prefetch" href="/assets/js/155.81d3ee1f.js"><link rel="prefetch" href="/assets/js/156.154a4ef2.js"><link rel="prefetch" href="/assets/js/16.e5eb6147.js"><link rel="prefetch" href="/assets/js/17.57853c4a.js"><link rel="prefetch" href="/assets/js/18.cb9d7518.js"><link rel="prefetch" href="/assets/js/19.f354dc47.js"><link rel="prefetch" href="/assets/js/2.570d8a23.js"><link rel="prefetch" href="/assets/js/20.b5af7fad.js"><link rel="prefetch" href="/assets/js/21.0b1928fe.js"><link rel="prefetch" href="/assets/js/22.f78666de.js"><link rel="prefetch" href="/assets/js/23.29c3f366.js"><link rel="prefetch" href="/assets/js/24.6f596516.js"><link rel="prefetch" href="/assets/js/25.14067b60.js"><link rel="prefetch" href="/assets/js/26.74ba4989.js"><link rel="prefetch" href="/assets/js/27.13d60edd.js"><link rel="prefetch" href="/assets/js/28.9523cb32.js"><link rel="prefetch" href="/assets/js/29.8ec842e9.js"><link rel="prefetch" href="/assets/js/3.3fb3d2e0.js"><link rel="prefetch" href="/assets/js/30.805597a8.js"><link rel="prefetch" href="/assets/js/31.831b195d.js"><link rel="prefetch" href="/assets/js/32.063c672d.js"><link rel="prefetch" href="/assets/js/33.6d93fac3.js"><link rel="prefetch" href="/assets/js/34.56e8263c.js"><link rel="prefetch" href="/assets/js/35.dbe688bb.js"><link rel="prefetch" href="/assets/js/36.dc5af2c1.js"><link rel="prefetch" href="/assets/js/37.0a7494f6.js"><link rel="prefetch" href="/assets/js/38.fe4fc171.js"><link rel="prefetch" href="/assets/js/39.f5ed5e92.js"><link rel="prefetch" href="/assets/js/4.2c405ec8.js"><link rel="prefetch" href="/assets/js/40.fe7e2714.js"><link rel="prefetch" href="/assets/js/41.30b0811d.js"><link rel="prefetch" href="/assets/js/42.76f52d62.js"><link rel="prefetch" href="/assets/js/43.e7bb0817.js"><link rel="prefetch" href="/assets/js/44.ead0e883.js"><link rel="prefetch" href="/assets/js/45.235df046.js"><link rel="prefetch" href="/assets/js/46.5f09e829.js"><link rel="prefetch" href="/assets/js/47.67116354.js"><link rel="prefetch" href="/assets/js/48.31f34543.js"><link rel="prefetch" href="/assets/js/49.10b5ebba.js"><link rel="prefetch" href="/assets/js/5.6f47322c.js"><link rel="prefetch" href="/assets/js/50.c0f0b7f1.js"><link rel="prefetch" href="/assets/js/51.5143f3bf.js"><link rel="prefetch" href="/assets/js/52.eeddfd48.js"><link rel="prefetch" href="/assets/js/53.eb790db5.js"><link rel="prefetch" href="/assets/js/54.8fe5421c.js"><link rel="prefetch" href="/assets/js/55.d8f9004b.js"><link rel="prefetch" href="/assets/js/56.62ac9b92.js"><link rel="prefetch" href="/assets/js/57.a9caec0d.js"><link rel="prefetch" href="/assets/js/58.f93fc522.js"><link rel="prefetch" href="/assets/js/59.a81a03aa.js"><link rel="prefetch" href="/assets/js/6.8c2ea393.js"><link rel="prefetch" href="/assets/js/60.ab782775.js"><link rel="prefetch" href="/assets/js/61.6dd12daf.js"><link rel="prefetch" href="/assets/js/62.76f4b01f.js"><link rel="prefetch" href="/assets/js/63.6f8a4742.js"><link rel="prefetch" href="/assets/js/64.6f8bb1fa.js"><link rel="prefetch" href="/assets/js/65.4120a44b.js"><link rel="prefetch" href="/assets/js/66.360c2d2b.js"><link rel="prefetch" href="/assets/js/67.26f84d32.js"><link rel="prefetch" href="/assets/js/68.68f45e5e.js"><link rel="prefetch" href="/assets/js/69.e311eb56.js"><link rel="prefetch" href="/assets/js/7.6762b2d7.js"><link rel="prefetch" href="/assets/js/70.cea82674.js"><link rel="prefetch" href="/assets/js/71.783ddcf7.js"><link rel="prefetch" href="/assets/js/72.e5467385.js"><link rel="prefetch" href="/assets/js/73.b8fb681b.js"><link rel="prefetch" href="/assets/js/74.1bae37db.js"><link rel="prefetch" href="/assets/js/75.024387e5.js"><link rel="prefetch" href="/assets/js/76.a8e53010.js"><link rel="prefetch" href="/assets/js/77.8c55500a.js"><link rel="prefetch" href="/assets/js/78.7ce90bf5.js"><link rel="prefetch" href="/assets/js/79.ef71713f.js"><link rel="prefetch" href="/assets/js/8.788a6364.js"><link rel="prefetch" href="/assets/js/80.acad589d.js"><link rel="prefetch" href="/assets/js/81.02670d10.js"><link rel="prefetch" href="/assets/js/82.53b7b1ac.js"><link rel="prefetch" href="/assets/js/83.99eb8581.js"><link rel="prefetch" href="/assets/js/84.d1535ce3.js"><link rel="prefetch" href="/assets/js/85.fe2b7de9.js"><link rel="prefetch" href="/assets/js/86.41850272.js"><link rel="prefetch" href="/assets/js/87.1cdc6df9.js"><link rel="prefetch" href="/assets/js/88.01bf3461.js"><link rel="prefetch" href="/assets/js/89.17c69819.js"><link rel="prefetch" href="/assets/js/9.3813842d.js"><link rel="prefetch" href="/assets/js/90.f6ae7e35.js"><link rel="prefetch" href="/assets/js/91.507bc284.js"><link rel="prefetch" href="/assets/js/92.90551782.js"><link rel="prefetch" href="/assets/js/93.dc442d78.js"><link rel="prefetch" href="/assets/js/94.315f4e94.js"><link rel="prefetch" href="/assets/js/95.ccd6c6bf.js"><link rel="prefetch" href="/assets/js/96.0c6d89d0.js"><link rel="prefetch" href="/assets/js/97.1a9f10a9.js"><link rel="prefetch" href="/assets/js/98.43be3caa.js"><link rel="prefetch" href="/assets/js/99.54c8207b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.0dbae9ec.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">whoway</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link router-link-active">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link router-link-active">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>NASM编译器常用指令</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#目录" class="sidebar-link">目录</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#_01-通用汇编指令" class="sidebar-link">01.通用汇编指令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#★分类" class="sidebar-link">★分类</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#★1-1-数据传送指令" class="sidebar-link">★1.1.数据传送指令</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#★1-2-算术和逻辑运算指令" class="sidebar-link">★1.2.算术和逻辑运算指令</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#★1-3-控制流指令" class="sidebar-link">★1.3.控制流指令</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#★1-4-其他指令" class="sidebar-link">★1.4.其他指令</a></li></ul></li><li><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#_02-nasm编译指令" class="sidebar-link">02.NASM编译指令</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#_03-cpu寄存器分类" class="sidebar-link">03.CPU寄存器分类</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#_3-1-用户可见" class="sidebar-link">3.1.用户可见</a></li><li class="sidebar-sub-header"><a href="/05.Engineer/%E6%B1%87%E7%BC%96%E8%AF%AD%E8%A8%80/03.NASM%E7%9A%84AT_T%E6%B1%87%E7%BC%96.html#_3-2-用户不可见" class="sidebar-link">3.2.用户不可见</a></li></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="nasm编译器常用指令"><a href="#nasm编译器常用指令" class="header-anchor">#</a> NASM编译器常用指令</h1> <h2 id="目录"><a href="#目录" class="header-anchor">#</a> 目录</h2> <p>[TOC]</p> <ul><li><font style="background:yellow;">32位汇编为例，结合X86寄存器理解</font></li> <li><code>NASM用的是intel汇编语法，和Linux反汇编的有区别</code></li></ul> <h2 id="_01-通用汇编指令"><a href="#_01-通用汇编指令" class="header-anchor">#</a> 01.通用汇编指令</h2> <h3 id="★分类"><a href="#★分类" class="header-anchor">#</a> ★分类</h3> <p>汇编指令通常可以分为数据传送指令，算术和逻辑预算指令，控制流指令</p> <p><code>PS：我们的操作数是:寄存器，立即数，内存</code></p> <h3 id="★1-1-数据传送指令"><a href="#★1-1-数据传送指令" class="header-anchor">#</a> ★1.1.数据传送指令</h3> <ul><li>1）mov 目标操作数,源操作数</li></ul> <blockquote><ul><li><code>mov 寄存器,寄存器</code></li> <li><code>mov 寄存器,立即数</code></li> <li><code>mov 寄存器,内存</code></li> <li><code>mov 内存,寄存器</code></li> <li><code>mov 内存,立即数</code></li> <li><font style="background:yellow;">mov 内存直接到内存是不准的！！</font></li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>mov byte ptr[var],5
mov eax,ebx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>2）push 操作数</li></ul> <blockquote><ul><li><code>push 寄存器</code>（注意要</li> <li><code>push 内存</code></li> <li><code>push 立即数</code></li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>push eax
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>3）pop 操作数</li></ul> <h3 id="★1-2-算术和逻辑运算指令"><a href="#★1-2-算术和逻辑运算指令" class="header-anchor">#</a> ★1.2.算术和逻辑运算指令</h3> <ul><li>1）加、减（add / <strong>sub</strong>tract，v.减去）</li></ul> <blockquote><ul><li><code>add/sub 目标操作数,被加/减的数字</code></li> <li><code>add/sub 寄存器,寄存器</code></li> <li><code>add/sub 寄存器,立即数</code></li> <li><code>add/sub 寄存器,内存</code></li> <li><code>add/sub 内存,寄存器</code></li> <li><code>add/sub 内存,立即数</code></li> <li><font style="background:yellow;">add/sub 内存,内存是不准的！！！</font></li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>sub eax,10		
;假设eax是变量，用C语言解释就是eax=eax-10
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>2）<code>带符号</code>乘法（<strong>mul</strong>tiplication,n.乘法）</li> <li>格式1）imul 目标操作数,操作数</li></ul> <blockquote><ul><li>imul 寄存器,寄存器</li> <li>imul 寄存器,内存</li> <li><font style="background:yellow;">Tips：只能是上面的，目标操作只能是寄存器</font></li></ul></blockquote> <ul><li>格式2）imul 目标操作数,操作数1,操作数2</li></ul> <blockquote><ul><li>imul 寄存器,寄存器,立即数</li> <li>imul 寄存器,内存,立即数</li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>;假设eax，edi是变量，用C语言解释就是eax=eax*edi
imul eax,edi
;假设eax，edi是变量，用C语言解释就是eax=edi*5
imul eax,edi,5
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><ul><li>3)<code>带符号</code>除法（division,n.除法）</li> <li>idiv 除数操作数</li></ul> <blockquote><ul><li>idiv 寄存器</li> <li>idiv 内存</li></ul> <blockquote><ul><li><font style="background:yellow;">被除数在<code>edx:eax</code>中，此外，操作结果，<code>商送到eax</code>,<code>余数送到edx</code></font></li></ul></blockquote></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>idiv ebx
idiv dword ptr [var]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>4）自加和自减（<strong>inc</strong>rease,v.增加 / <strong>dec</strong>rease,v.减少）</li></ul> <blockquote><ul><li>inc/dec 操作数</li> <li>inc/dec 寄存器</li> <li>inc/dec 内存</li> <li><font style="background:yellow;">inc/dec 立即数显然是不准！！！</font></li></ul> <blockquote><ul><li>这就是C语言中<code>i++,--i</code>的汇编实现</li></ul></blockquote></blockquote> <ul><li>5）取负（<strong>neg</strong>ative，v.否定，adj.负面的）</li></ul> <blockquote><ul><li>neg 操作数</li> <li>neg 寄存器</li> <li>neg 内存</li> <li><font style="background:yellow;">neg  立即数	显然是不准！！！</font></li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>neg eax
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><font style="background:red;">位运算大类指令</font></p> <ul><li>6）按位取反（位翻转）指令（not）</li></ul> <blockquote><ul><li>not 操作数</li> <li><code>not 寄存器</code></li> <li><code>not 内存</code></li> <li><font style="background:yellow;">not  立即数	显然是不准！！！</font></li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>not byte ptr [var]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>7）<font style="background:yellow;">逻辑</font>移位指令（<strong>sh</strong>ift v.移动，转移）</li></ul> <blockquote><ul><li>shl/shr（left，逻辑左移/right，逻辑右移）</li> <li>shl/shr 被操作数,移位的位数的操作数</li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>shl eax,1
shr ebx,2  
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li><p>8）<font style="background:yellow;">算术</font>移位指令（<strong>sh</strong>ift v.移动，转移）
（arithmetic，n.算术，算术运算）</p></li> <li><p>9）逻辑与，或，异或（and/or/xor）</p></li></ul> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>and eax,0fH
or eax,0fH
xor edx,edx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="★1-3-控制流指令"><a href="#★1-3-控制流指令" class="header-anchor">#</a> ★1.3.控制流指令</h3> <ul><li>1）循环(loop)（可以说是C语言中循环的汇编语言实现）</li></ul> <blockquote><ul><li>loop 地址</li></ul> <blockquote><ul><li>loop指令，在执行的时候，会顺序做两件事：（1）寄存器cx减一  （2）如果cx的内容不为0，则转移到指定的位置去执行，否则顺序执行后面的指令。</li></ul></blockquote></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>mov cx,5 ;循环次数
mov si,10 ;除数
digit:
     xor dx,dx
	 div si
	 mov [bx],dl ;保存数位
	 inc bx
	 loop digit
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><ul><li>2）跳转（jump)（可以说是C语言中goto的汇编语言实现）</li></ul> <blockquote><ul><li>jmp 标签所在地址</li></ul></blockquote> <div class="language-.asm line-numbers-mode"><pre class="language-text"><code>begin: 
add eax,1
jmp begin
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>3）比较和转移（可以说是C语言条件语句的汇编语言实现）</li></ul> <blockquote><ul><li>指令（1）cmp 操作数,操作数</li></ul> <blockquote><ul><li>cmp 寄存器,寄存器</li> <li>cmp 寄存器,立即数</li> <li>cmp 寄存器,内存</li> <li>cmp 内存,寄存器</li></ul> <blockquote><ul><li>比较两个操作数的值，并且根据结果，设置eflags寄存器中的条件码</li></ul></blockquote></blockquote> <ul><li>指令（2）j开头的转移指令</li></ul> <table><thead><tr><th>语法</th> <th>说明</th></tr></thead> <tbody><tr><td>je 标签</td> <td>jump when  <strong>equal</strong></td></tr> <tr><td>jne 标签</td> <td>jump when <strong>not equal</strong></td></tr> <tr><td>jz 标签</td> <td>jump when <strong>last reult was zero</strong></td></tr> <tr><td>jg 标签</td> <td>jump when <strong>greater than</strong></td></tr> <tr><td>jge 标签</td> <td>jump when <strong>greater than or equal to</strong></td></tr> <tr><td>jl 标签</td> <td>jump when <strong>less than</strong></td></tr> <tr><td>jle 标签</td> <td>jump when <strong>less than or equal to</strong></td></tr></tbody></table> <ul><li>代码样例</li></ul></blockquote> <div class="language-.asm line-numbers-mode"><pre class="language-text"><code>begin:
	inc ebx
	cmp eax,ebx		;比较
	jge begin		;当eax&gt;=ebx的时候，就跳转到begin
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><ul><li>4）子程序调用（C语言中函数调用的汇编实现，也解释了为什么我们自己模拟的栈比C语言自身的栈消耗资源更少）</li> <li>指令1）函数调用（call）</li> <li>指令2）函数返回（ret）</li></ul> <blockquote><ul><li>call指令：(语法: call 标签)
首先：将<code>当前执行指令</code>的<code>地址</code>入栈
然后：无条件转移到由标签指示的地址的指令
Tips：和简单的跳转指令（jmp）不同，call指令保存调用之前的地址信息</li> <li>ret指令:(语法:  ret)
实现子程序的返回机制
ret指令首先：弹出栈中保存的指令地址
然后：无条件转移到保存的指令地址处执行</li></ul></blockquote> <blockquote><ul><li>用一个C语言反汇编说明（测试环境VS2012反汇编）</li></ul></blockquote> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>省略——————
int test(int a,int b)
{
00D41460  push        ebp  
00D41461  mov         ebp,esp  
00D41463  sub         esp,0C0h  
00D41469  push        ebx  
00D4146A  push        esi  
00D4146B  push        edi  
00D4146C  lea         edi,[ebp-0C0h]  
00D41472  mov         ecx,30h  
00D41477  mov         eax,0CCCCCCCCh  
00D4147C  rep stos    dword ptr es:[edi]  
	return a+b;
00D4147E  mov         eax,dword ptr [a]  
00D41481  add         eax,dword ptr [b]  
}
00D41484  pop         edi  
00D41485  pop         esi  
00D41486  pop         ebx  
00D41487  mov         esp,ebp  
00D41489  pop         ebp  
00D4148A  ret 			 ;调用返回
省略------------
	int a=3;
00D413EE  mov         dword ptr [a],3  
	int b=7;
00D413F5  mov         dword ptr [b],7  
	int c=test(a,b);
00D413FC  mov         eax,dword ptr [b]  
00D413FF  push        eax  
00D41400  mov         ecx,dword ptr [a]  
00D41403  push        ecx  
00D41404  call        _test (0D4114Ah)  ;_test是函数的符号表，编译原理中讲过。此次调用test函数
00D41409  add         esp,8  
00D4140C  mov         dword ptr [c],eax  
省略------------
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br></div></div><h3 id="★1-4-其他指令"><a href="#★1-4-其他指令" class="header-anchor">#</a> ★1.4.其他指令</h3> <ul><li><p>cld指令（clear Direction Flag）
无操作数指令。
将标志寄存器（flags）的DF（Direction Flag，方向标志位）置0
0表示，movsb或者movsw等指令的传送方向是正向的（从低地址到高地址）</p></li> <li><p>std指令（set Direction Flag）
无操作数指令。
将标志寄存器（flags）的DF（Direction Flag，方向标志位）置0
1表示，movsb或者movsw等指令的传送方向是反向的（从高地址到低地址）</p></li> <li><p>movsb（move string byte)
无操作数指令。
把数据从一个地方批量传送（复制）到另一个地方，是以byte为单位</p></li> <li><p>movsw（move string word)
无操作数指令。
把数据从一个地方批量传送（复制）到另一个地方，是以word（字）为单位</p></li> <li><p>movsb和movsw要是只写他，而不加rep，则它们只能执行一次
如果想要处理器自动的反复执行，那么要加上指令前缀rep(repeat)
意思是cx（count Register）不为0则反复执行，</p></li></ul> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>rep mobsw
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="_02-nasm编译指令"><a href="#_02-nasm编译指令" class="header-anchor">#</a> 02.NASM编译指令</h2> <p>也就是我们所说的伪指令，不是CPU的指令</p> <p>1）db/dw声明一些数据
用伪指令db声明的数据都只有一个字节的长度
用伪指令db声明的数据都只有一个字的长度</p> <div class="language-.asm line-numbers-mode"><pre class="language-text"><code>db -1	;初始化为0xFF
dw -1	;初始化为0xFFFF
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>2）times 是一个比较实用伪指令，用来重复定义数据或指令。</p> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>times 510-($-$$) db 0
dw 0xaa55	
;这段代码经常出现在 boot 磁盘 MBR 引导代码中
;目的是除了最后 2 个字节和 code 代码外的区域全部写 0 值
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>times 还可以使用在重复写某一条指令</p> <div class="language-asm line-numbers-mode"><pre class="language-text"><code>times 10 nop
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-txt line-numbers-mode"><pre class="language-text"><code>这段代码结果是重复填入了 10 条 nop 指令：

00000000  90                nop
00000001  90                nop
00000002  90                nop
00000003  90                nop
00000004  90                nop
00000005  90                nop
00000006  90                nop
00000007  90                nop
00000008  90                nop
00000009  90                nop
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="_03-cpu寄存器分类"><a href="#_03-cpu寄存器分类" class="header-anchor">#</a> 03.CPU寄存器分类</h2> <blockquote><p>CPU中寄存器大致分为两类</p></blockquote> <h3 id="_3-1-用户可见"><a href="#_3-1-用户可见" class="header-anchor">#</a> 3.1.用户可见</h3> <p><code>可以对这类寄存器编程</code>
eg.
通用寄存器组<br>
程序状态字寄存器</p> <h3 id="_3-2-用户不可见"><a href="#_3-2-用户不可见" class="header-anchor">#</a> 3.2.用户不可见</h3> <p><code>不可以对这类寄存器编程</code>
eg.<br>
存储器地址寄存器（MAR）<br>
存储器数据寄存器（MDR）<br>
指令寄存器（IR）</p></div> <div class="page-edit"><!----> <!----></div> <!----> </div> <!----></div></div>
    <script src="/assets/js/app.c70e21ad.js" defer></script><script src="/assets/js/118.c6ae6572.js" defer></script>
  </body>
</html>
